home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1892 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.1 KB  |  55 lines

  1. Path: oxy.rust.net!usenet
  2. From: ebennett@rust.net
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q]Assigning function pointer in C/C++.
  5. Date: Sun, 14 Jan 1996 01:06:28 GMT
  6. Organization: Rust Net - High Speed Internet in Detroit  810-642-2276
  7. Message-ID: <4d9ab7$pj1@oxy.rust.net>
  8. References: <DL3JJu.5nB.0.queen@torfree.net>
  9. NNTP-Posting-Host: liv-20.rust.net
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. bh332@freenet.toronto.on.ca (Karim Ladha) wrote:
  13.  
  14. >How is it possible to assign a declared variable in C++ a pointer to
  15. >some function member? If you know of a solution, post. Greatly appreciated.
  16.  
  17. >In C for example;
  18.  
  19. >...
  20. >void( far *MyFunc )();
  21. >...
  22. >...
  23.  
  24. >Thank you,
  25. >  Karim A.Ladha - BH332@TorFree.Net
  26.  
  27. >PS: Using BC++ v4.0 for Windows(tm) - DOS Application.
  28.  
  29. >-- 
  30.  
  31. The syntax for class member function pointers is a little different.
  32. For example:
  33.  
  34.  class MyClass {
  35.    public:
  36.       void aFunction ();
  37.  };
  38.  
  39.  typeptr (MyClass::*MyFuncPtr) ();
  40.  
  41. will make MyFuncPtr the correct type.  Then:
  42.  
  43.   MyFuncPtr ptr;
  44.   ptr = &MyClass::aFunction;
  45.  
  46. To call it, given x is an instance of MyClass:
  47.  
  48.    (x->ptr)();
  49.  
  50. will call it.
  51.  
  52. Earl
  53.  
  54.  
  55.